package com.kfm.dao.impl;

import com.kfm.dao.AccountDao;
import com.kfm.model.Account;
import org.apache.commons.dbutils.QueryRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;

//@Component("accountDao")
@Repository("dao") // 持久层 bean
public class AccountDaoImpl implements AccountDao {

    @Autowired
    private QueryRunner queryRunner;

    @Override
    public int insert(Account account) {
        try {
            return queryRunner.update("insert into account(username, pass) values(?, ?)", account.getUsername(), account.getPass());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return -1;
    }
}
